/**
 * 
 */
package com.mvc.service.healthmanager.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mvc.dao.BaseDaoI;
import com.mvc.framework.constant.GlobalConstant;
import com.mvc.model.healthmanager.archive.Electrocardio;
import com.mvc.model.healthmanager.archive.Temperature;
import com.mvc.service.healthmanager.EcgManagerServiceI;
import com.mvc.utils.CreatHighChartJson;

/**
 * @author qingjie
 *
 */
@Service
public class EcgManagerServiceImpl implements EcgManagerServiceI {
	
	@Autowired
	private BaseDaoI<Electrocardio> eDaoI;
	
	private final String titleName = "心率数据走势";
	private final String unit = "次/分钟";
	private final String yAxixname = "心率(次/分钟)";

	@Override
	public List<Electrocardio> getEcgList(Electrocardio electrocardio) {
		return eDaoI.find("from Electrocardio e where e.personId = '"+electrocardio.getPersonId() +"'"+ electrocardio.getOrder());
	}
	
	@Override
	public String getJsonData(String personId) {
		List<Electrocardio> list = eDaoI.find("from Electrocardio e where e.personId = '"+personId+"'");
		String[] xAxis = new String[list.size()];
		Map<String, Object> map = new HashMap<String, Object>();
		if(!list.isEmpty()){
			Map<String, Object> tem_m = new HashMap<String, Object>();
			tem_m.put("name", "心率(次/分钟)");
			List<String> tem_l = new ArrayList<String>();
			
			for(int i=0;i<list.size();i++){
				Electrocardio e = list.get(i);
				xAxis[i] = GlobalConstant.SDF.format(e.getCreateDate());
				tem_l.add(i,e.getHeaterate());
			}
			tem_m.put("data", tem_l);
			map.put("temperature", tem_m);
		}
		return CreatHighChartJson.CreatJsonData(titleName, unit, yAxixname, xAxis, map);
	}

}
